﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics.Contracts;
using System.ComponentModel.DataAnnotations;

namespace YasharEl.Infrastructure.EntityModel.Validation.DataAnnotations
{
    public class DataAnnotationsInvalidValueInfo : IInvalidValueInfo
    {
        #region Fields

        private readonly ValidationAttribute _validationAttribute;

        #endregion

        #region Constructors

        public DataAnnotationsInvalidValueInfo(Type entityType, string propertyName, ValidationAttribute validationAttribute)
        {
            Contract.Requires<ArgumentNullException>(entityType != null, "entityType could not be null.");
            Contract.Requires<ArgumentNullException>(!string.IsNullOrEmpty(propertyName), "entityInstance could not be null or empty.");
            Contract.Requires<ArgumentNullException>(validationAttribute != null, "validationAttribute could not be null.");

            EntityType = entityType;
            PropertyName = propertyName;
            _validationAttribute = validationAttribute;
        }

        #endregion

        #region IInvalidValueInfo Implementations

        public Type EntityType
        {
            get;
            private set;
        }

        public string PropertyName
        {
            get;
            private set;
        }

        public string Message
        {
            get
            {
                // TODO : Return localized error message...
                return _validationAttribute.ErrorMessage;
            }
        }

        #endregion
    }
}
